package com.sunshine.lnuplus.utils

import android.content.*
import android.net.Uri
import androidx.fragment.app.FragmentManager
import com.sunshine.lnuplus.R
import com.sunshine.lnuplus.model.SuperData
import com.sunshine.lnuplus.model.room.TimetableRepository
import com.sunshine.lnuplus.view.DialogWithoutView
import es.dmoral.toasty.Toasty
import java.lang.Exception

/**
 * Created by sunshine on 2020/4/3
 */

object TellMeDialog{

    fun tellMe(context: Context, fragmentManager: FragmentManager, error: Boolean, message: String, repository: TimetableRepository?){
        var title = "开发者模式"
        var negative: DialogInterface.OnClickListener? = null
        if(error){
            title = "哎呀，课程表好像出了些问题"
            negative = DialogInterface.OnClickListener { _, _ ->
                repository?.deleteAllLesson()
                Toasty.info(context, "数据库清除成功~，重启Shine课程表即可~").show()
            }
        }
        DialogWithoutView.newInstance(
            title,
            message,
            false,
            DialogInterface.OnClickListener { _, _ ->
                (context.getSystemService(Context.CLIPBOARD_SERVICE) as ClipboardManager).setPrimaryClip(
                    ClipData.newPlainText("Label", message))
                try{
                    context.startActivity(Intent(Intent.ACTION_VIEW, Uri.parse(context.resources.getString(R.string.qq_url))))
                    Toasty.info(context, "在QQ聊天对话框长按粘贴就可以啦，谢谢你的反馈~", Toasty.LENGTH_LONG).show()
                }catch (e: Exception){
                    Toasty.warning(context, context.resources.getString(R.string.not_found_qq)).show()
                }
            },
            negative).show(fragmentManager, "tell_me")
    }
}